<template>
	<view class="u-padding-top-45">
		<u-swiper class="swiper" v-if="lists.length > 0 && showStatus" :height="630" :effect3dPreviousMargin="140" :list="lists" :link="link" :qrCode="qrCode"
			:effect3d="true" bg-color="transparent" mode="none"></u-swiper>
		
		<image src="https://resource.lanbaozixun.com/uploads/images/20240630220738138ec5494.png" mode="widthFix" class="poster-icon"></image>
	</view>
</template>

<script>
	import {
		baseURL,
		basePath
	} from '@/config/app'
	import {
		mapGetters
	} from 'vuex'
	import {
		getInviteBanner
	} from "@/api/user";
	import {
		// apiMnpQrCode,
		getShareMnQrcode,
		getPosterLists
	} from "@/api/app";
	import {
		Tips
	} from "@/utils/tools.js";
	export default {
		data() {
			return {
				showStatus:true,
				qrCode: '',
				imgUrl: '',
				lists: []
			};
		},
		created() {
			this.getPosterListsFun();
			// #ifdef MP-WEIXIN
			this.showStatus = false
			this.getMnpQrCode()
			// #endif
		},
		methods: {
			async getPosterListsFun() {
				let d = await getPosterLists()
				this.lists = d.data
		
			},
			saveImageToAlbum() {
				// 下载网络图片到本地
				uni.downloadFile({
					url: this.imgUrl,
					success: res => {
						// #ifndef H5
						uni.saveImageToPhotosAlbum({
							filePath: res.tempFilePath,
							success: res => {
								console.log(res, "success")
								this.$toast({
									title: "保存成功"
								});
							},
							fail: err => {
								console.log(err, 'fail')
							}
						});
						// #endif
						// #ifdef H5
						this.$toast({
							title: 请长按图片保存
						})
						// #endif
					}
				});
			},
			getMnpQrCode() {
				getShareMnQrcode({
						id: '', // 商品id或其他活动id
						url: 'pages/index/index', // 跳转页面路径
						type: 0, // 0-会员分享海报 1-商品详情 2-砍价活动
					})
					.then((res) => {
						this.showStatus = true
						this.qrCode = res.data.qr_code
					})
			},
			handleSuccess(val) {
				this.imgUrl = val
			},
			getInviteBannerFun() {
				// #ifdef H5 || APP-PLUS
				let path = '/'
				// #endif
				// #ifdef MP-WEIXIN
				let path = 'pages/index/index'
				// #endif
				getInviteBanner({
					url: path
				}).then(res => {
					if (res.code == 1) {
						this.imgUrl = res.data.url
					}
				});
			}
		
		},
		computed: {
			...mapGetters(['inviteCode', 'userInfo']),
		
			link() {
				return `https://dtm.lanbaozixun.com/mobile/pages/index/index?invite_code=${this.inviteCode}`
			}
		}
	}
</script>

<style lang="scss">
	.poster-icon{
		width: 148rpx;
		display: block;
		margin: 20rpx auto 10rpx;
	}
</style>